package net.kts.subskill.tel.embassy;

import java.util.ArrayList;

import net.kts.main.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EmbassyAdapter extends BaseAdapter {

	private ArrayList<EmbassyVO> embList;
	private LayoutInflater mInflater;
	
	
	public EmbassyAdapter(Context c) {
		mInflater = LayoutInflater.from(c);
		mInflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public void setData(ArrayList<EmbassyVO> poolList) {
		embList = poolList;
	}

	// List count 얻기
	@Override
	public int getCount() {
		return embList.size();
	}

	// List item 얻기
	@Override
	public Object getItem(int position) {
		return embList.get(position);
	}

	// List item Id 얻기
	@Override
	public long getItemId(int position) {
		return position;
	}

	// 화면에 보여지는 List item 의 모양을 setting
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {
			// List 한 row의 item 모양을 정의한 xml을 설정
			convertView	=  mInflater.inflate(R.layout.tel_embassy_row, null);
			
			// xml에 포함된 widget instance 얻기
			holder = new ViewHolder();
			holder.nameTxt 		= (TextView) convertView.findViewById(R.id.tv_name);
			holder.engTxt		= (TextView) convertView.findViewById(R.id.tv_eng); 
			holder.telTxt 		= (TextView) convertView.findViewById(R.id.tv_tel);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		// 값 출력
		EmbassyVO embassy 	= embList.get(position);
		
		holder.nameTxt.setText(embassy.getName());
		holder.engTxt.setText(embassy.getEng());
		holder.telTxt.setText(embassy.getTel());
		
		return convertView;
	}
	
	// xml의 위젯 instance 얻기위한 view holder
	static class ViewHolder {
		TextView nameTxt;
		TextView engTxt;
		TextView telTxt;
	}

}
